package class_test.test2_0428;

/**
 * @author haomin
 * @date 2022/04/28 22:12
 **/
import java.util.ArrayList;
import java.util.Date;

public class Test11_8 {
    public static void main(String[] args) {
        NewAccount a1 = new NewAccount("George",1122,1000);
        a1.setAnnualInterestRate(1.5);
        a1.deposit(30);
        a1.deposit(40);
        a1.deposit(50);
        a1.withDraw(5);
        a1.withDraw(4);
        a1.withDraw(2);
        System.out.println("姓名：" + a1.getName() + "，利率：" + a1.getAnnualInterestRate()
                + "%,收支额：" + a1.getBalance());
        System.out.println();
        for (int i = 0; i < a1.list.size(); i++) {
            System.out.println( a1.list.get(i).toString());
        }
    }
}
class NewAccount{
    private int id;
    private double balance;//收支额
    private double annualInterestRate;//当前利率
    private Date dateCreated; //开户日期
    private String name;
    ArrayList<Transaction> list = new ArrayList<Transaction>();
    public NewAccount(String name,int id){}
    public NewAccount(){

    }
    public NewAccount(int id,double balance){
        this.id = id;
        this.balance = balance;
    }
    public NewAccount(String name,int id,double balance){
        this.name = name;
        this.id = id;
        this.balance = balance;
    }
    public String getName(){
        return name;
    }
    public int getId(){
        return id;
    }
    public void setId(int id){
        this.id = id;
    }
    public double getBalance(){
        return balance;
    }
    public void setBalance(double balance){
        this.balance = balance;
    }
    public double getAnnualInterestRate(){
        return annualInterestRate;
    }
    public void setAnnualInterestRate(double annualInterestRate){
        this.annualInterestRate = annualInterestRate;
    }
    public Date getDateCreated(){
        dateCreated = new Date();
        return dateCreated  ;
    }
    public double getMonthlyInterestRate(){
        double monthlyInterestRate =  balance * ((annualInterestRate/100)/12);
        return monthlyInterestRate;
    }
    public void withDraw(double money){  //取钱
        if(balance > money){
            balance = balance - money;
            list.add(new Transaction('W',money,balance,"取出"));
        }else{
            System.out.println("取出失败！");
        }
    }
    public void deposit(double money){  //存钱
        balance = balance + money;
        list.add(new Transaction('D',money,balance,"存入"));
    }
}
class Transaction{
    private java.util.Date date;
    private char type;//交易类型  W代表取款，D代表存款
    private double amount;//交易量
    private double balance;//交易后的新余额
    private String description;//交易描述
    public Transaction(char type,double amount,double balance,String description){
        this.type = type;
        this.amount = amount;
        this.balance = balance;
        this.description = description;
    }

    @Override
    public String toString() {
        return
                " 交易类型：" + type +
                        ", 交易量" + amount +
                        "$, 交易后新余额：" + balance +
                        "$, 交易描述:" + description;
    }
}